from moviepy.editor import VideoFileClip
import os


def convert_mp4_to_avi(input_file, output_file):
    if not os.path.isfile(input_file):
        print(f"输入文件 {input_file} 不存在。")
        return

    try:
        # 加载视频文件
        clip = VideoFileClip(input_file)

        # 将视频导出为AVI格式
        clip.write_videofile(output_file, codec='libxvid')
        print(f"视频已成功转换为 {output_file}")

    except Exception as e:
        print(f"转换过程中发生错误: {e}")


if __name__ == "__main__":
    input_mp4 = "input_video.mp4"  # 输入的MP4文件路径
    output_avi = "output_video.avi"  # 输出的AVI文件路径

    convert_mp4_to_avi(input_mp4, output_avi)